package com.zzk.lanouhn.myapplication1.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.adapters.MyFragmentAdapter;
import com.zzk.lanouhn.myapplication1.fragments.MsgAttenetionArticleFragment;
import com.zzk.lanouhn.myapplication1.fragments.MsgAttenetionShowFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/9/1.
 */
public class AttenetionDetailsActivity extends AppCompatActivity {

    private ViewPager vp_content_details;
    private TabLayout tab_title_details;
    private ImageView iv_back_details;
    private List<String> tabnames;
    private List<Fragment> fragments;
    private MyFragmentAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attenetiondetails);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        vp_content_details = (ViewPager) findViewById(R.id.vp_attenetion_contents_details);
        tab_title_details = (TabLayout) findViewById(R.id.tab_attenetion_details);
        iv_back_details = (ImageView) findViewById(R.id.iv_back_attenetion);
    }

    private void initData() {
        tabnames = new ArrayList<>();
        tabnames.add("文章");
        tabnames.add("晒单");
        fragments = new ArrayList<>();
        MsgAttenetionArticleFragment articleFragment = new MsgAttenetionArticleFragment();
        fragments.add(articleFragment);
        MsgAttenetionShowFragment showFragment = new MsgAttenetionShowFragment();
        fragments.add(showFragment);
        adapter = new MyFragmentAdapter(getSupportFragmentManager(), tabnames, fragments);
        vp_content_details.setAdapter(adapter);
        tab_title_details.setupWithViewPager(vp_content_details);

    }

    private void initEvent() {
        iv_back_details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
